package model;

import java.util.Observable;

import model.location.ScreenArea;
import model.location.WorldArea;

public class Snippet extends Observable
{
	private String _id;
	
	//Information from webservice
	private WorldArea _worldArea;
	private DisplayType _displayType; 	
	//variable data
	private boolean _information; // for now a boolean that indicates red or green, expand in other sprint
	
	private ScreenArea _screenArea;	
	private boolean _inArea;
	
	public Snippet(String id, WorldArea worldArea, boolean information, int type)
	{
		setId(id);
		_worldArea = worldArea;
		
		setInformation(information);
		setDisplayType(DisplayType.PLAINTEXT);
		
		_inArea = false;
		//setDisplayType(DisplayType.values()[type]);
	}
	
	public String getId() {
		return _id;
	}

	public void setId(String id) {
		this._id = id;
	}
	
	public WorldArea getWorldArea()
	{
		return _worldArea;
	}

	public DisplayType getDisplayType() {
		return _displayType;
	}

	public void setDisplayType(DisplayType displayType) {
		this._displayType = displayType;
	}

	public boolean isInformation() {
		return _information;
	}

	public void setInformation(boolean information) {		
		this._information = information;
		
	}
	
	public void setScreenArea(ScreenArea screenArea)
	{
		_screenArea = screenArea;
	}
	
	public ScreenArea getScreenArea()
	{
		return _screenArea;
	}
	
	public boolean isInArea()
	{
		return _inArea;
	}
	
	public void setInArea(boolean inArea)
	{
		_inArea = inArea;
	}

	@Override
	public void notifyObservers() 
	{
		setChanged();
		super.notifyObservers();
	}
	
	@Override
	public void notifyObservers(Object data) {
		setChanged();
		super.notifyObservers(data);
	}

	public Snippet update(Snippet snippet) 
	{
		setScreenArea(snippet.getScreenArea());
		setInformation(snippet.isInformation());
		this.notifyObservers();
		return null;
	}

	@Override
	public String toString() 
	{
		if(!_inArea)
			return String.format("ID: %s\nWorldArea: %s\nDisplayType: %s\nInfo: %s", _id, getWorldArea().toString(), getDisplayType().toString(), isInformation());
		return String.format("ID: %s\nnWorldArea: %s -> \nScreenArea: %s\nDisplayType: %s\nInfo: %s", _id, getWorldArea().toString(), getScreenArea().toString(), getDisplayType().toString(), isInformation());
	}
}